﻿using System.Net;
using System.Net.Http;
using System.Web.Http;
using DotNetNuke.Services.Social.Messaging.Internal;
using DotNetNuke.Services.Social.Notifications;
using DotNetNuke.Web.Api;

namespace MessageCenterAlerts.API
{
    public class CountsController : DnnApiController
    {
        [SupportedModules("MessageCenterAlerts")]
        [HttpGet]
        [DnnAuthorize]
        public HttpResponseMessage Get()
        {
            object result;

            if(UserInfo == null)
            {
                result = new { success = false };
            }
            else
            {
                result = new
                {
                    success = true,
                    counts = new
                    {
                        notificationCount = NotificationsController.Instance.CountNotifications(UserInfo.UserID, PortalSettings.PortalId),
                        messageCount = InternalMessagingController.Instance.CountUnreadMessages(UserInfo.UserID, PortalSettings.PortalId)
                    }
                };
            }

            return Request.CreateResponse(HttpStatusCode.OK, result);
        }
    }
}